package com.yanxu.order;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/5/22-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class AllOrder {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer();

        producer.setNamesrvAddr("139.129.91.21:9876");
        producer.setSendMsgTimeout(5000);
        producer.setDefaultTopicQueueNums(1);  //设置 queue 只有1个，这样保证所有消息全部发送到这一个队列中。

        for (int i = 0; i < 10; i++) {
            Message message = new Message(
                    "all-order-message",
                    "tag-all-order",
                    "key-all-order", ("message_" + i).getBytes()
            );
            SendResult sendResult = producer.send(message);
        }

        producer.start();
    }
}